<?php
include "../../../lib/list.php";
if($mode == 'search'){
	$sbuyer = $_POST['buyer'];
	$startdate = $_POST['startdate'];
	$enddate = $_POST['enddate'];

	if($sbuyer){
		$sear_char .= " and uatp_buyer.name like '%$sbuyer%' ";
	}
	if($startdate){
		$sear_char .= " and uatp_prdgroup.date >= '$startdate' ";
	}
	if($enddate){
		$sear_char .= " and uatp_prdgroup.date <= '$enddate' ";
	}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-us">
<head>
<link rel="stylesheet" href="../../../css/list.css" type="text/css"></link>
<link rel="stylesheet" href="../../../css/insert.css" type="text/css"></link>
<link rel="stylesheet" href="../../../css/table.sorter.css" type="text/css" media="print, projection, screen" />
<link type="text/css" rel="stylesheet" href="../../../css/dhtmlgoodies_calendar.css?random=20051112" media="screen"></link>

<script type="text/javascript" src="../../../js/dhtmlgoodies_calendar.js?random=20060118"></script>
<script type="text/javascript" src="../../../js/list.js"></script>
<script type="text/javascript" src="../../../js/jquery-1.2.6.js"></script>
<script type="text/javascript" src="../../../js/jquery.tablesorter.js"></script>
<script type="text/javascript">
function search(){
	document.detail.mode.value 	 = 'search';
	document.detail.target		 = 'right';
	document.detail.action		 = 'view.php';
	document.detail.method		 = 'post';
	document.detail.submit();
}
function page_move(page){
	document.detail.mode.value = 'search';
	document.detail.page.value = page;
	document.detail.target = 'right';
	document.detail.action = 'view.php';
	document.detail.method = 'post';
	document.detail.submit();
}
$(function(){
	$("table")
		.tablesorter({headers: {             
		   		0: {               
       		     // 정렬선택 안함
       		     sorter: false         
       		    },1: {               
        		     // 정렬선택 안함
        		     sorter: false         
     		    },2: {               
        		     // 정렬선택 안함
        		     sorter: false         
     		    },3: {               
         		     // 정렬선택 안함
         		     sorter: false         
      		    },4: {               
        		     // 정렬선택 안함
        		     sorter: false         
        		},5: {               
            		 // 정렬선택 안함
            		 sorter: false         
            	},6: {               
                	 // 정렬선택 안함
                	 sorter: false         
                },7: {               
                   	 // 정렬선택 안함
                   	 sorter: false         
                },8: {               
                  	 // 정렬선택 안함
                  	 sorter: false         
                  	}         
       		   }, widthFixed: false})
});
</script>
</head>
<body>
	<div style="width: 1024px;">
		<div
			style="border-bottom: 1px solid #e8e8e8; text-align: left; font-size: 12px; margin-bottom: 12px; color: #9a9a9a">:::
			재고 관리&nbsp;⇒&nbsp;구입관리표</div>
		<form name="search" method="post" action="iframe.php" enctype=multipart/form-data>
					
		</form>
			<form name="detail" method="post" action="query.php" enctype=multipart/form-data>
						<input name="mode" value="insert" type="hidden"/>
						<input type="hidden" name="page" value=""/>
						
			<table cellspacing="1" class="tablesorter" style="width:750px;float:left;">
			<thead>
				<tr>
								<th colspan="2">전표번호</th>
								<th>구입처</th>
								<th colspan="2">점포명</th>
								<th style="width:30px;"><center>출력</center></th>
				</tr>
			</thead>
			<thead>
				<tr>
								<th style="width:10px;">&nbsp;</th>
								<th style="width:100px;">barcode</th>
								<th style="width:410px;">상품명</th>
								<th style="width:80px;">수량</th>
								<th colspan="2" style="width:150px;">구입금액</th>
				</tr>
			</thead>
			<?php 
			$page=$_POST['page'];
			
			$sql = "SELECT uatp_product.productname, uatp_product.barcode, uatp_prdreview.count,uatp_prdreview.s_no,
                                uatp_prdreview.admin_name, uatp_shopinfo.name AS 'shopname', uatp_prdreview.price,
								uatp_prdreview.unit, uatp_product.buyer, uatp_buyer.name, uatp_prdgroup.date
								FROM uatp_prdreview 
								INNER JOIN uatp_shopinfo ON uatp_prdreview.s_no = uatp_shopinfo.no
		     		        	INNER JOIN uatp_product ON uatp_prdreview.p_no = uatp_product.no 
		                        INNER JOIN uatp_prdgroup ON uatp_prdreview.date = uatp_prdgroup.date
		                        INNER JOIN uatp_buyer ON uatp_product.buyer = uatp_buyer.no
								WHERE 1 AND uatp_prdreview.unit='0'";
			$total = DBnumrows($sql);
			
			$scale=15;
			if ($page == ''){
				$page=1;
			}
			
			$cpage = intval($page);//현재 페이지
			$totalpage = intval($total/$scale); //전체 페이지 갯수
			if ($totalpage*$scale != $total)
			$totalpage = $totalpage + 1;
			
			if ($cpage ==1) {
				$cline = 0 ;
			} else {
				$cline = ($cpage*$scale) - $scale ;
			}
			
			$limit=$cline+$scale;
			
			if ($limit >= $total)
			$limit=$total;
			
			$scale1 = $limit - $cline;
			
			$query = $sql." ORDER BY g_no DESC, buyer ASC LIMIT $cline, $scale1";
			$total = DBnumrows($query);
			$result = DBquery($query);
			
			for($i=1; $list = mysql_fetch_array($result); $i++){
			if($bunho != date('Ymd',strtotime($list['date']))."-".$list['g_no'] || $list['name']!=$buyer){
				$buyer = $list['name'];
				$bunho = date('Ymd',strtotime($list['date']))."-".$list['g_no'];
				?>
			<tbody>
			<tr>
				<td colspan="2" style="background:#efefef;"><?=$bunho?></td>
				<td style="background:#efefef;"><?=$buyer?></td>
				<td colspan="2"  style="background:#efefef;"><?=$list['shopname']?></td>
				<td style="background:#efefef;"><center>
				<a href="javascript:openBrWindow('print.php?buyer=<?=$list['buyer']?>&date=<?=date('Y-m-d',strtotime($list['date']))?>&g_no=<?=$list['g_no']?>','mbid','scrollbars=no,width=700,height=600');" style="width:80px;">
				출력</a></center></td>
			</tr>
			</tbody>
			<?php }?>
			<tbody>
			<tr>
				<td>&nbsp;</td>
				<td><?=$list['barcode']?></td>
				<td><?=$list['productname']?></td>
				<td style="text-align:right;"><?=$list['count']?>&nbsp;개&nbsp;</td>
				<td colspan="2"  style="text-align:right;"><?=$list['price']?>&nbsp;￥&nbsp;</td>
			</tr>
			</tbody>
			<?php 
				}
				mysql_free_result($result);
			?>
		</table>
			<div style="width:250px;float:right;">		 <table class="entry fixed H_15px" summary="재고-입력상단부">
						     <tr>
						      <th style="width:30%">점포그룹</th>
						      <td><?=$sg_name?></td>
						</tr>
						<tr>
							  <th>점포명</th>
							  <td><?=$s_name?></td>
						</tr>
						<tr>
							<th>시작날짜</th>
							<td><input type='text' name='startdate' value="<?=$startdate?>" readonly class="default" style="width:100px;"  
						onclick="displayCalendar(this,'yyyy/mm/dd',this);"/></td>
						</tr>
						<tr>
							<th>종료날짜</th>
							<td><input type='text' name='enddate' value="<?=$enddate?>" readonly class="default" style="width:100px;"  
						onclick="displayCalendar(this,'yyyy/mm/dd',this);"/></td>
						</tr>
						<tr>
							<th>구매처</th>
							<td colspan="3"><input type='text' name='buyer' value="<?=$sbuyer?>" class="default" style="width:100px;"/></td>
						</tr>
						</table>
									
						<div style="padding-top:15px;width:250px;float:right;">
						<center><a href="javascript:search()" class="button blue small" style="width:150px;">&nbsp;검색하기&nbsp;</a></center>
						</div>	
						</div>	
		<div style="text-align:left;float:left;padding:0;margin:0;width:700px;">
		<?php page_avg($totalpage,$cpage);?>	
						</div>
						
					
			</form>
	</div>
</body>
</html>
